package com.github.vertical_blank.sqlformatter.Demo;

import com.github.vertical_blank.sqlformatter.SqlFormatter;
import com.github.vertical_blank.sqlformatter.core.FormatConfig;
import com.github.vertical_blank.sqlformatter.languages.Dialect;

import java.util.Arrays;

/**
 *
 */
public class SqlFormatterDemo {

    public static void main(String[] args) {
        //m1();
        m2();
        //System.out.println(String.join("", findBeforeWhitespace("select distinct tenant_platform.platformname, platform.enname platformenname")));
    }

    public static void m2() {
        String sql = "sql-->name[adultedu.scoreinput.synthesizescore.getidscount],param[20002,1798992014056882177,1714839796282556419,1714036903265697794,1728520390760726530,1751720864422821889,1626791173835194369,1705706442422484993,1749743800734973954,1735844580486545410,1735844591146369026,1714385798541869057,1713300613378342913,1630483157605154819,1626791146754670593,1626791147174100993,1626791147630231553,1626791151106260993,1626791149948633089,1626791175823294465,1774480457426010114,1625596542235705347,1714839796167213059,1714839796089618435,1626791148503695361,1798992521828761601,1713293846119448577,1713295702961946626,1744362306791276546,1714752047974187011,1713307576316198914,1713292855815962625,1713292422066208769,1641806753226031105,1629875811277340674,1735844635891204098,1629875855616376834,1640553719549394945,1626789159930691585,1629875615635079170,1708415812403986434,1713586967336189954,1713133526852829185,1655686274923626498,1729326686291361815,1729791839550046231,1671064404056080386,1764207739240710146,1713932622078410754,1649971669158068226,1635397849095077889,1660032336543088643,1643199937419149314,1643199976525791234,1626789177991364609,1677348237321699330,1667380400215818242,1767667177096216578,1783859132700295170,1766856071781023746,1764207619508011010,1735844686944272386,1713663027287425027,1661661555534594050,1661661604230463490,1713663027248627715,1626789587992969217,1626789575572586497,1739471853873790978,1643177618319605762,1627052991089475585,1775007020829638679,1643177592191188994,1643191731198361602,1675613165305462786,1643197988126851074,1643197938984288258,1626789596424568833,1767195200338264065,1701985152069009410,1711656214716219394,1702985866597629954,1713303987098222594,1717205679727443970,1696998980856053762,1680142371459694594,1653960418074296322,1653802004130037762,1702688675980115970,1645618376623521794,1680696602372603906,1626789476393025537,1630958743492493314,1626789489418436609,1702143636823605250,1626789483167875073,1700353334933716994,1713596324486578178,1650879881133686786,1650071374498103298,1631023577313574914,1717460886578266114,1643190988267585538,1651233880106074114,1626789468605251585,1713596471697211394,1643190974381293570,1736482003354648578,1626789545432317953,1626789533387325441,1626789551390326785,1626789538695217153],use[68],sql[select count(0) from ( select id, studentid, courseversionid, exambatchid, examscheduleid, examercourseid, examstudentbooking. status, tenantid from examstudentbooking where examstudentbooking.tenantid = ? and examstudentbooking.exambatchid =? and examstudentbooking.courseversionid in (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) and examstudentbooking.examscheduleid in (?) and examstudentbooking.entrystatus= 1 and examstudentbooking.isdelete = 0 and examstudentbooking. status in (1, 2) ) examstudentbooking inner join studentfileinfo on studentfileinfo.studentid = examstudentbooking.studentid and studentfileinfo.isdelete = 0 and 1=1 and studentfileinfo.tenantid = examstudentbooking.tenantid and studentfileinfo.stationid in (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) and studentfileinfo.gradeid in (?,?,?,?,?) and studentfileinfo.majorid in (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) and studentfileinfo.learningformid in (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) and studentfileinfo.studentlayerid in (?,?,?,?,?) inner join studentinfo on studentinfo.id = examstudentbooking.studentid and studentinfo.isdelete = 0 inner join useraccount on useraccount.id = studentinfo.useraccountid and useraccount.isdelete = 0 inner join startedcourse on startedcourse.studentid = examstudentbooking.studentid and startedcourse.courseversionid = examstudentbooking.courseversionid and startedcourse.datastatus = 1 and startedcourse.isdelete = 0 and startedcourse.status in (0,1,2) inner join courseversion on examstudentbooking.courseversionid = courseversion.id and courseversion.isdelete = 0 left join student_class on studentfileinfo.studentid = student_class.studentid and student_class.tenantid = examstudentbooking.tenantid left join class on student_class.classid = class.id and class.tenantid = examstudentbooking.tenantid and class.isdelete = 0 left join exambatch on examstudentbooking.exambatchid = exambatch.id and exambatch.isdelete = 0 left join totalscore on totalscore.examstudentbookingid = examstudentbooking.id and totalscore.tenantid = examstudentbooking.tenantid and totalscore.exambatchid = examstudentbooking.exambatchid and totalscore.isdelete = 0 left join dayscore on dayscore.studentid = examstudentbooking.studentid and dayscore.courseversionid = examstudentbooking.courseversionid and dayscore.tenantid = examstudentbooking.tenantid and dayscore.isdelete = 0 left join testscore on testscore.studentid = examstudentbooking.studentid and testscore.courseversionid = examstudentbooking.courseversionid and testscore.tenantid = examstudentbooking.tenantid and testscore.isdelete = 0 left join investigationscore on investigationscore.studentid = examstudentbooking.studentid and investigationscore.courseversionid = examstudentbooking.courseversionid and investigationscore.tenantid = examstudentbooking.tenantid and investigationscore.isdelete = 0 left join attendancescore on attendancescore.studentid = examstudentbooking.studentid and attendancescore.courseversionid = examstudentbooking.courseversionid and attendancescore.tenantid = attendancescore.tenantid and attendancescore.isdelete = 0 left join belowtaskscore on examstudentbooking.studentid = belowtaskscore.studentid and courseversion.id = belowtaskscore.courseversionid and belowtaskscore.isdelete = 0 left join examstudenttestqualification on examstudenttestqualification.exambatchid = examstudentbooking.exambatchid and examstudenttestqualification.courseversionid = examstudentbooking.courseversionid and examstudenttestqualification.studentid = examstudentbooking.studentid and examstudenttestqualification.isdelete = 0 where (totalscore.publishstatus=0 or totalscore.publishstatus is null) and totalscore.calculationstatus is null and dayscore.id is not null and testscore.id is not null and investigationscore.id is not null and attendancescore.id is not null and belowtaskscore.id is not null;],login[1750255607942742017],guid[2d5fc4a8b5054db88e40fccd76eb0376]^";
        sql = "sql-->name[adultedu.scoreinput.synthesizescore.getlist],param[30002,1780254755436625923,1717402718696374277,1653872120168448003,1782795943866793989,1780889475608477699,1780896802441003013,1805968593197727747,1688024975916662789,1762389007015084035,1779075599242887171,1779075619135422469,1773002374945701893,1773002389181169669,1683224783139897347,1715944868444897285,1737662050431139844,1707762206775443461,1715944844808945669,1712035078909984773,1656057494673293315,1683212450993799173,1645815550460297221,1806630314936631301,1674958658675408899,1674958615869390851,1643709324992708613,1641288342207201284,1684117457043718148,1698084097026424835,1639379611475247107,1780254806656417797,1766946851313942532,1641086298745733125,1718108849900093445,1662647080885157893,1638197077282390019,1690909261496844291,1641079121412882435,1658876280771182595,1662939925205483525,1696649677077741573,1721623252849131524,1636757021024845830,1704604236178784261,1746359376147382275,1637192668450652163,1642622976598736901,1663374913276215301,1653872561882136579,1655307116499435525,1636751720048492547,1636751727083388931,1640718026290495493,1663488679202521091,1641810068976435203,1655144979471794181,1641078539204689923,1642622955839029253,1636751348156334083,1636684945026973701,1698158529371701251,30002,0],use[99],sql[select studentfileinfo.gradename,studentfileinfo.stationname,studentfileinfo.studentlayername,studentfileinfo.majorname,studentfileinfo.learningformname,class.classname,studentinfo.realname,studentfileinfo.studentno,studentinfo.cardnum,useraccount.username,studentinfo.examineenum,studentfileinfo.studentcategoryid,courseversion.versionname,semester.semestername,startedcourse.status learningstatus,totalscore.publishstatus,totalscore.examtype,totalscore.scorestatus,totalscore.calculationstatus,exambatch.batchname,examscore.examstatus,examscore.score examscore,startedcourse.studydurationstatus,startedcourse.coursewarecountstatus,examstudenttestqualification.cantaketest, examstudentbooking. status examstudentbookingstatus, totalscore.score totalscore, ifnull(examtasknum.tasknum, 0) tasknum, examscore.id examscoreid, dayscore.id dayscoreid, testscore.id testscoreid, investigationscore.id investigationscoreid, attendancescore.id attendancescoreid, belowtaskscore.id belowtaskscoreid, totalscore.id, studentfileinfo.studentid, studentfileinfo.gradeid, studentfileinfo.stationid, studentfileinfo.learningformid, studentfileinfo.majorid, studentfileinfo.studentlayerid, studentfileinfo.teachplanid, totalscore.calculationstatus calculationstatuskey, totalscore.publishstatus publishstatuskey, courseversion.id courseversionid, exambatch.id batchid, examschedule.id examscheduleid, examstudentbooking.id bookingid, online_courseversion.id onlinecourseversionid, examform.isallotexamroom, teachplan_courseversion.resulttype as scoretype, dayscore.score param4, testscore.score param64, attendancescore.score param128, investigationscore.score param256, totalscore.score, totalscore.belowtaskscore from ( select id, studentid, courseversionid, exambatchid, examscheduleid, examercourseid, examstudentbooking. status, tenantid from examstudentbooking where examstudentbooking.tenantid = ? and examstudentbooking.exambatchid =? and examstudentbooking.courseversionid in (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) and examstudentbooking.examscheduleid in (?) and examstudentbooking.isdelete = 0 and examstudentbooking. status in (1, 2) ) examstudentbooking inner join studentfileinfo on studentfileinfo.studentid = examstudentbooking.studentid and studentfileinfo.isdelete = 0 and 1=1 and studentfileinfo.tenantid = examstudentbooking.tenantid and studentfileinfo.stationid in (?,?,?,?,?) and studentfileinfo.gradeid in (?) and studentfileinfo.majorid in (?,?,?,?,?,?,?,?,?,?,?,?,?) and studentfileinfo.learningformid in (?,?,?,?,?) and studentfileinfo.studentlayerid in (?,?,?,?,?,?) inner join studentinfo on studentinfo.id = examstudentbooking.studentid and studentinfo.isdelete = 0 inner join useraccount on useraccount.id = studentinfo.useraccountid and useraccount.isdelete = 0 inner join startedcourse on startedcourse.studentid = examstudentbooking.studentid and startedcourse.courseversionid = examstudentbooking.courseversionid and startedcourse.datastatus = 1 and startedcourse.isdelete = 0 and startedcourse.status in (0,1,2) inner join courseversion on examstudentbooking.courseversionid = courseversion.id and courseversion.isdelete = 0 inner join teachplan_courseversion on teachplan_courseversion.courserversionid = examstudentbooking.courseversionid and teachplan_courseversion.isdelete = 0 and studentfileinfo.teachplanid = teachplan_courseversion.teachplanid left join student_class on studentfileinfo.studentid = student_class.studentid left join class on student_class.classid = class.id and class.isdelete = 0 left join exambatch on examstudentbooking.exambatchid = exambatch.id and exambatch.isdelete = 0 left join examercourse on examercourse.id = examstudentbooking.examercourseid and examercourse.isdelete = 0 left join examform on examercourse.examformid = examform.id and examercourse.isdelete = 0 left join online_courseversion on online_courseversion.courseversionid = examstudentbooking.courseversionid and online_courseversion.isdelete = 0 and online_courseversion.exambatchid = examstudentbooking.exambatchid left join totalscore on totalscore.examstudentbookingid = examstudentbooking.id and totalscore.isdelete = 0 and totalscore.exambatchid = examstudentbooking.exambatchid left join examscore on examscore.examstudentbookingid = examstudentbooking.id and examscore.isdelete = 0 left join dayscore on dayscore.studentid = examstudentbooking.studentid and dayscore.courseversionid = examstudentbooking.courseversionid and dayscore.tenantid = examstudentbooking.tenantid and dayscore.isdelete = 0 left join testscore on testscore.studentid = examstudentbooking.studentid and testscore.courseversionid = examstudentbooking.courseversionid and testscore.tenantid = examstudentbooking.tenantid and testscore.isdelete = 0 left join investigationscore on investigationscore.studentid = examstudentbooking.studentid and investigationscore.courseversionid = examstudentbooking.courseversionid and investigationscore.tenantid = examstudentbooking.tenantid and investigationscore.isdelete = 0 left join attendancescore on attendancescore.studentid = examstudentbooking.studentid and attendancescore.courseversionid = examstudentbooking.courseversionid and attendancescore.tenantid = attendancescore.tenantid and attendancescore.isdelete = 0 left join belowtaskscore on examstudentbooking.studentid = belowtaskscore.studentid and courseversion.id = belowtaskscore.courseversionid and belowtaskscore.isdelete = 0 left join examtasknum on examstudentbooking.courseversionid = examtasknum.courseversionid and examtasknum.isdelete = 0 and examtasknum.tenantid = ? and examtasknum.orgid = ? left join examschedule on examstudentbooking.examscheduleid = examschedule.id and examschedule.isdelete = 0 and examstudentbooking.exambatchid = examschedule.exambatchid left join semester on semester.id = teachplan_courseversion.semesterid and semester.isdelete = 0 left join examstudenttestqualification on examstudenttestqualification.exambatchid = examstudentbooking.exambatchid and examstudenttestqualification.courseversionid = examstudentbooking.courseversionid and examstudenttestqualification.studentid = examstudentbooking.studentid and examstudenttestqualification.isdelete = 0 where (totalscore.publishstatus=0 or totalscore.publishstatus is null) and totalscore.calculationstatus is null order by studentfileinfo.studentno asc, convert(courseversion.versionname using gbk) asc limit 0,50;],login[1660751816414986241],guid[fb777abd6cbd446a900f4523cc5bd21b]^";
        sql = "SELECT c.customer_name AS customer, o.order_id AS order_id, oi.product_id AS product_id, p.product_name AS product_name, p.avg_price AS average_price, s.supplier_name AS supplier, CASE WHEN p.avg_price > 50 THEN 'Expensive' ELSE 'Affordable' END AS price_category FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id AND o.order_date BETWEEN '2024-01-01' AND '2024-08-19' LEFT JOIN order_items oi ON o.order_id = oi.order_id AND oi.quantity > 0 LEFT JOIN ( SELECT product_id, AVG(price) AS avg_price FROM products GROUP BY product_id ) p ON oi.product_id = p.product_id LEFT JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE c.customer_id IN (1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050) UNION ALL SELECT c.customer_name AS customer, NULL AS order_id, NULL AS product_id, NULL AS product_name, NULL AS average_price, NULL AS supplier, NULL AS price_category FROM customers c WHERE c.customer_id NOT IN ( SELECT DISTINCT customer_id FROM orders WHERE order_date BETWEEN '2024-01-01' AND '2024-08-19' ) ORDER BY customer ASC, order_id ASC;";
        System.out.println(SqlFormatter.formatSass(sql));
    }
    public static void m1() {
        String sqlStr = "select distinct tenant_platform.PlatFormName, platform.enname platformenname, tenant_platform.logourl platformlogourl, tenant.name tenantname, tenant.logourl tenantlogourl, tenant_platform.domain, tenant.id tenantid, platform.id platformid, tenant_platform.fullname, tenant.copyright, tenant.address, tenant.schoolname, tenant.mobile, tenant.collegename, tenant.postcode, tenant.loginlogo, tenant.status tenantstatus, tenant_platform.status, platform.authzlevel from tenant_platform inner join platform on platform.id = tenant_platform.platformid inner join tenant on tenant.id = tenant_platform.tenantid and tenant.isdelete = 0 where tenant_platform.domain = ? order by platform.id limit 1, 5 ;";
        sqlStr = "SELECT stufilechangeapply.GradeID          AS newGradeId\n" + "       , stufilechangeapply.MajorID        AS newMajorId\n" + "       , stufilechangeapply.LearningFormID AS newLearnformId\n" + "       , stufilechangeapply.StudentLayerID AS newLayerId\n" + "       , stufilechangeapply.NativeCity     AS newNativeCity\n" + "       , stufilechangeapply.NativeProvince AS newNativeProvince\n" + "       , studentfileinfo.id\n" + "       , stufilechangeapply.id             AS changeApplyId\n" + "       , studentfileinfo.StudentCategoryID\n" + "       , studentinfo.Political\n" + "       , studentinfo.Nation\n" + "       , studentinfo.NativeCity\n" + "       , studentinfo.NativeProvince\n" + "       , studentfileinfo.stationId\n" + "       , sdf1.StudentFileBatchName\n" + "       , stufilechangeapply.RealName       AS newrealname\n" + "       , stufilechangeapply.cardnum        AS newcardnum\n" + "       , stufilechangeapply.political      AS newpolitical\n" + "       , stufilechangeapply.nation         AS newnation\n" + "       , sdf2.studentfilebatchname         AS newstudentfilebatchname\n" + "       , grade.gradename                   AS newgradename\n" + "       , studentlayer.LayerName            AS newLayerName\n" + "       , major.majorname                   AS newmajorname\n" + "       , learningform.LearnFormName        AS newLearnFormName\n" + "       , station.stationname               AS newstationname\n" + "       , station.id                        AS newStationId\n" + "       , newClass.ClassName                AS newClassName\n" + "       , stufilechangeapply.oldClassName\n" + "       , modifyuser.`Name`                 AS collegeAuditBy\n" + "       , stufilechangeapply.ModifyDate     AS collegeAuditDate\n" + "       , #field\n" + "FROM   studentfileinfo\n" + "       INNER JOIN studentinfo ON StudentInfo.ID = studentfileinfo.StudentID\n" + "                  AND studentinfo.isdelete = 0\n" + "       INNER JOIN useraccount ON useraccount.ID = StudentInfo.UserAccountID\n" + "                  AND useraccount.IsDelete = 0\n" + "       #biao\n" + "       LEFT JOIN userinfo ON userinfo.UserAccountID = stufilechangeapply.CreateBy\n" + "                 AND userinfo.IsDelete = 0\n" + "                 AND userinfo.`STATUS` = 1\n" + "       LEFT JOIN userinfo AS modifyuser ON modifyuser.UserAccountID = stufilechangeapply.ModifyBy\n" + "                 AND modifyuser.IsDelete = 0\n" + "                 AND modifyuser.`STATUS` = 1\n" + "       INNER JOIN stuchargestandard ON stuchargestandard.studentid = studentfileinfo.studentid\n" + "                  AND stuchargestandard.isdelete = 0\n" + "       LEFT JOIN studentfilebatch AS sdf1 ON sdf1.isdelete = 0\n" + "                 AND sdf1.id = studentfileinfo.studentfilebatchid\n" + "       LEFT JOIN studentfilebatch AS sdf2 ON sdf2.isdelete = 0\n" + "                 AND sdf2.id = stufilechangeapply.studentfilebatchid\n" + "       LEFT JOIN grade ON grade.isdelete = 0\n" + "                 AND grade.id = stufilechangeapply.GradeID\n" + "       LEFT JOIN studentlayer ON studentlayer.isdelete = 0\n" + "                 AND studentlayer.id = stufilechangeapply.StudentLayerID\n" + "       LEFT JOIN major ON major.isdelete = 0\n" + "                 AND major.id = stufilechangeapply.MajorID\n" + "       LEFT JOIN learningform ON learningform.isdelete = 0\n" + "                 AND learningform.id = stufilechangeapply.LearningFormID\n" + "       LEFT JOIN station ON station.isdelete = 0\n" + "                 AND station.id = stufilechangeapply.StationID\n" + "       LEFT JOIN student_class ON student_class.StudentId = studentfileinfo.StudentID\n" + "       LEFT JOIN class ON class.id = student_class.ClassId\n" + "                 AND class.IsDelete = 0\n" + "       LEFT JOIN class newClass ON newClass.id = stufilechangeapply.classid\n" + "                 AND newClass.isdelete = 0\n" + "WHERE\n" + "\tstudentfileinfo. STATUS IN (0, 1)\n" + "AND studentfileinfo.IsDelete = 0\n" + "AND studentfileinfo.RegisterStatus = 1\n" + "AND studentfileinfo.StudentFileBatchID = @StudentFileBatchId\n" + "AND studentfileinfo.StationID = @StationId\n" + "AND studentfileinfo.GradeID = @GradeId\n" + "AND studentfileinfo.StudentLayerID = @StudentLayerId\n" + "AND studentfileinfo.MajorID = @MajorId\n" + "AND studentfileinfo.LearningFormID = @LearningFormId\n" + "AND stufilechangeapply.AuditingStatus = @AuditingStatus\n" + "AND StudentInfo.RealName LIKE '%' @RealName '%'\n" + "AND useraccount.UserName LIKE '%' @UserName '%'\n" + "AND StudentInfo.ExamineeNum LIKE '%' @ExamineeNum '%'\n" + "AND studentfileinfo.StudentNo LIKE '%' @StudentNo '%'\n" + "AND StudentInfo.CardNum LIKE '%' @CardNum '%'\n" + "AND class.ClassName LIKE '%' @ClassNameStr '%'\n" + "AND studentfileinfo.TenantID = @TenantId\n" + "AND studentfileinfo.OrgID = @OrgId\n" + "AND stufilechangeapply.id IN (#ids)\n" + "ORDER BY #SortName #SortType";
        sqlStr = "select studentfileinfo.gradename,studentfileinfo.stationname,studentfileinfo.studentlayername,studentfileinfo.majorname,studentfileinfo.learningformname,class.classname,studentinfo.realname,studentfileinfo.studentno,studentinfo.cardnum,useraccount.username,studentinfo.examineenum,studentfileinfo.studentcategoryid,courseversion.versionname,semester.semestername,startedcourse.status learningstatus,totalscore.publishstatus,totalscore.examtype,totalscore.scorestatus,totalscore.calculationstatus,exambatch.batchname,examscore.examstatus,examscore.score examscore,startedcourse.livingscorestatus, examstudentbooking. status examstudentbookingstatus, totalscore.score totalscore, ifnull(examtasknum.tasknum, 0) tasknum, examscore.id examscoreid, dayscore.id dayscoreid, testscore.id testscoreid, investigationscore.id investigationscoreid, attendancescore.id attendancescoreid, belowtaskscore.id belowtaskscoreid, totalscore.id, studentfileinfo.studentid, studentfileinfo.gradeid, studentfileinfo.stationid, studentfileinfo.learningformid, studentfileinfo.majorid, studentfileinfo.studentlayerid, studentfileinfo.teachplanid, totalscore.calculationstatus calculationstatuskey, totalscore.publishstatus publishstatuskey, courseversion.id courseversionid, exambatch.id batchid, examschedule.id examscheduleid, examstudentbooking.id bookingid, online_courseversion.id onlinecourseversionid, examform.isallotexamroom, teachplan_courseversion.resulttype as scoretype, dayscore.score param4, testscore.score param64, attendancescore.score param128, investigationscore.score param256, totalscore.score, totalscore.belowtaskscore from ( select id, studentid, courseversionid, exambatchid, examscheduleid, examercourseid, examstudentbooking. status, tenantid from examstudentbooking where examstudentbooking.tenantid = ? and examstudentbooking.exambatchid =? and examstudentbooking.courseversionid in (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) and examstudentbooking.examscheduleid in (?) and examstudentbooking.entrystatus= 2 and examstudentbooking.isdelete = 0 and examstudentbooking. status in (1, 2) ) examstudentbooking inner join studentfileinfo on studentfileinfo.studentid = examstudentbooking.studentid and studentfileinfo.isdelete = 0 and 1=1 and studentfileinfo.tenantid = examstudentbooking.tenantid and studentfileinfo.stationid in (?,?,?,?,?) and studentfileinfo.gradeid in (?) and studentfileinfo.majorid in (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) and studentfileinfo.learningformid in (?,?) and studentfileinfo.studentlayerid in (?,?,?) inner join studentinfo on studentinfo.id = examstudentbooking.studentid and studentinfo.isdelete = 0 inner join useraccount on useraccount.id = studentinfo.useraccountid and useraccount.isdelete = 0 inner join startedcourse on startedcourse.studentid = examstudentbooking.studentid and startedcourse.courseversionid = examstudentbooking.courseversionid and startedcourse.datastatus = 1 and startedcourse.isdelete = 0 and startedcourse.status in (0,1,2) inner join courseversion on examstudentbooking.courseversionid = courseversion.id and courseversion.isdelete = 0 inner join teachplan_courseversion on teachplan_courseversion.courserversionid = examstudentbooking.courseversionid and teachplan_courseversion.isdelete = 0 and studentfileinfo.teachplanid = teachplan_courseversion.teachplanid left join student_class on studentfileinfo.studentid = student_class.studentid left join class on student_class.classid = class.id and class.isdelete = 0 left join exambatch on examstudentbooking.exambatchid = exambatch.id and exambatch.isdelete = 0 left join examercourse on examercourse.id = examstudentbooking.examercourseid and examercourse.isdelete = 0 left join examform on examercourse.examformid = examform.id and examercourse.isdelete = 0 left join online_courseversion on online_courseversion.courseversionid = examstudentbooking.courseversionid and online_courseversion.isdelete = 0 and online_courseversion.exambatchid = examstudentbooking.exambatchid left join totalscore on totalscore.examstudentbookingid = examstudentbooking.id and totalscore.isdelete = 0 and totalscore.exambatchid = examstudentbooking.exambatchid left join examscore on examscore.examstudentbookingid = examstudentbooking.id and examscore.isdelete = 0 left join dayscore on dayscore.studentid = examstudentbooking.studentid and dayscore.courseversionid = examstudentbooking.courseversionid and dayscore.tenantid = examstudentbooking.tenantid and dayscore.isdelete = 0 left join testscore on testscore.studentid = examstudentbooking.studentid and testscore.courseversionid = examstudentbooking.courseversionid and testscore.tenantid = examstudentbooking.tenantid and testscore.isdelete = 0 left join investigationscore on investigationscore.studentid = examstudentbooking.studentid and investigationscore.courseversionid = examstudentbooking.courseversionid and investigationscore.tenantid = examstudentbooking.tenantid and investigationscore.isdelete = 0 left join attendancescore on attendancescore.studentid = examstudentbooking.studentid and attendancescore.courseversionid = examstudentbooking.courseversionid and attendancescore.tenantid = attendancescore.tenantid and attendancescore.isdelete = 0 left join belowtaskscore on examstudentbooking.studentid = belowtaskscore.studentid and courseversion.id = belowtaskscore.courseversionid and belowtaskscore.isdelete = 0 left join examtasknum on examstudentbooking.courseversionid = examtasknum.courseversionid and examtasknum.isdelete = 0 and examtasknum.tenantid = ? and examtasknum.orgid = ? left join examschedule on examstudentbooking.examscheduleid = examschedule.id and examschedule.isdelete = 0 and examstudentbooking.exambatchid = examschedule.exambatchid left join semester on semester.id = teachplan_courseversion.semesterid and semester.isdelete = 0 left join examstudenttestqualification on examstudenttestqualification.exambatchid = examstudentbooking.exambatchid and examstudenttestqualification.courseversionid = examstudentbooking.courseversionid and examstudenttestqualification.studentid = examstudentbooking.studentid and examstudenttestqualification.isdelete = 0 where (totalscore.publishstatus=0 or totalscore.publishstatus is null) and totalscore.calculationstatus is null and dayscore.id is null and testscore.id is null and investigationscore.id is null and attendancescore.id is null and belowtaskscore.id is null order by studentfileinfo.studentno asc, convert(courseversion.versionname using gbk) asc limit 0,50;";
        String sql =  SqlFormatter.of(Dialect.MySql).format(sqlStr,
                FormatConfig.builder()
                        .indent("    ") // Defaults to two spaces
                        .uppercase(true) // Defaults to false (not safe to use when SQL dialect has case-sensitive identifiers)
                        .linesBetweenQueries(1) // Defaults to 1
                        .maxColumnLength(100) // Defaults to 50
                        .params(Arrays.asList("XXX", "b", "c")) // Map or List. See Placeholders replacement.
                        .skipWhitespaceNearBlockParentheses(true)
                        //.lineBreaksWithComma(2)
                        .build()
        );
        System.out.println(sql);
    }

    public static String[] findBeforeWhitespace(String input) {
        int index = 0;
        char[] chars = input.toCharArray();
        int beforeLength = chars.length;
        while (index != beforeLength && Character.isWhitespace(chars[index])) {
            index++;
        }
        return new String[] {
                new String(chars, 0, index), new String(chars, index, beforeLength - index)
        };
    }
}
